<?php 
	require 'includes/class.phpmailer.php';
  require 'includes/class.smtp.php';
  include("includes/connection.php");

	$name = $_POST['name'];
	$email = $_POST['email'];
	$request = $_POST['request'];
	$valid = false;

	$sql = "INSERT INTO tb_email (nama, email, text) VALUES ('$name', '$email', '$request')";
	if ($query = mysql_query($sql)) {
		$valid = true;

    $htmlEmail = "<div style='font-family: Helvetica, serif; background-color: #ECF0F1; color: #777777; border-radius: 4px;'><div style='text-align: center; padding: 30px; background-color: #1ABC9C; color: #ECF0F1; border-top-left-radius: 4px; border-top-left-radius: 4px;'>Request From Website</div><div class='content' style='padding: 30px; border-bottom-left-radius: 4px; border-bottom-left-radius: 4px;'><table style='color: #777777; border-collapse: collapse;'><tr><td style='min-width: 100px; padding: 5px; line-height: 140%; vertical-align: top;'>Name</td><td style='padding: 5px; line-height: 140%; vertical-align: top;'>:</td><td style='padding: 5px; line-height: 140%; vertical-align: top;'>$name</td></tr><tr><td style='padding: 5px; line-height: 140%; vertical-align: top;'>Email</td><td style='padding: 5px; line-height: 140%; vertical-align: top;'>:</td><td style='padding: 5px; line-height: 140%; vertical-align: top;'>$email</td></tr><tr><td style='padding: 5px; line-height: 140%; vertical-align: top;'>Text</td><td style='padding: 5px; line-height: 140%; vertical-align: top;'>:</td><td style='padding: 5px; line-height: 140%; vertical-align: top;'>$request</td></tr></table></div></div>";
    
    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    try {
      $mail->SMTPDebug  = 2;                                // enables SMTP debug information (for testing)
      $mail->SMTPAuth   = true;                             // enable SMTP authentication
      $mail->SMTPSecure = "ssl";                            // sets the prefix to the servier
      $mail->Host       = "bali.webserversystems.com";      // sets GMAIL as the SMTP server
      $mail->Port       = "465";                            // set the SMTP port for the GMAIL server
      $mail->Username   = "info@4zure.com";                 // GMAIL username
      $mail->Password   = "4zur3l4zuli";                    // GMAIL password
      
      //Set who the message is to be sent from
      $mail->From = "info@4zure.com";                       //From Address -- CHANGE --
      $mail->FromName = "Info 4zure";
      
      //Set who the message is to be sent to
      $mail->AddAddress("karis@4zure.com");
      $mail->AddAddress("latamaosadi@4zure.com");
      $mail->AddAddress("mika@4zure.com");
      $mail->AddAddress("bhaskara@4zure.com");
      //Set the subject line
      $mail->Subject = "Request From Website";
      //Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
      $mail->MsgHTML($htmlEmail);

      //Send the message, check for errors
      if($mail->Send()) {
        $dataJSON["msg"] = 0;
      }
    } catch (phpmailerException $e) {
      // echo $e->errorMessage(); //Pretty error messages from PHPMailer
        $dataJSON["msg"] = 1;
    } catch (Exception $e) {
      // echo $e->getMessage(); //Boring error messages from anything else!
        $dataJSON["msg"] = 0;
    }
	}
?>